package main

import (
	"chapter-02-protoc/service"
	"encoding/json"
	"google.golang.org/protobuf/proto"
	"log"
)

func main() {
	//声明变量
	user := &service.User{
		Username: "张三",
		Age:      18,
	}
	//结构体转化buf
	marshalUser, err := proto.Marshal(user)
	if err != nil {
		panic(err)
	}
	log.Println(marshalUser)
	newUser := &service.User{}
	err = proto.Unmarshal(marshalUser, newUser)
	if err != nil {
		panic(err)
	}
	res, err := json.Marshal(newUser)
	if err != nil {
		panic(err)
	}
	log.Println(string(res))
}
